/**
 * Baijiahulian.com Inc. Copyright (c) 2014-2016 All Rights Reserved.
 */
package com.baijia.authentication.principal.credentials;

import com.baijia.authentication.AccountType;
import com.baijia.authentication.handler.support.encoder.PasswordEncoder;
import com.baijia.authentication.handler.support.encoder.PlainTextPasswordEncoder;
import com.baijia.authentication.principal.Credentials;

/**
 * @title UserCredentials
 * @desc TODO
 * @author macrohuang
 * @date Jan 20, 2016
 * @version 1.0
 */
public class UserCredentials extends Credentials {

    private static final long serialVersionUID = 495805010113129529L;

    private String username;
    private String password;
    private Boolean sms = false;

    private transient PasswordEncoder encoder;

    public UserCredentials(String username, String password) {
        this(username, password, false);
    }

    public UserCredentials(String username, String password, Boolean isSms) {
        this(username, password, isSms, new PlainTextPasswordEncoder());
    }

    public UserCredentials(String username, String password, Boolean isSms, PasswordEncoder encoder) {
        this.username = username;
        this.encoder = encoder;
        this.sms = isSms;
        this.password = this.encoder.encode(password);
    }

    @Override
    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return this.encoder.decode(password);
    }

    public Boolean isSms() {
        return sms;
    }

    public Integer getAccountType() {
        return AccountType.USER.getCode();
    }

    @Override
    public String toString() {
        return "{username: " + username + ", password: ***}";
    }
}
